﻿<%@ Page Language="C#" MasterPageFile="~/MasterPages/Core.Master" AutoEventWireup="true"
    CodeBehind="RolesList.aspx.cs" Inherits="Pap.Web.Modules.Membership.Views.RolesList" Title="<%$Resources:PageTitle %>" %>

<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <script type="text/javascript">
        function GridRefreshed() {
            Ext.getCmp('txtRoleName').reset();
        }

        var ApplyFilter = function(store) {
            store.filterBy(getRecordFilter());
        }

        var filterString = function(value, dataIndex, record) {
            var val = record.get(dataIndex);
            if (typeof val != "string") {
                return true;
            }
            if (value.length == 0) {
                return value.length == 0;
            }
            return val.toLowerCase().indexOf(value.toLowerCase()) > -1;
        }

        var getRecordFilter = function() {
            var f = [];

            f.push({
                filter: function(record) {
                    return filterString(Ext.getCmp('txtRoleName').getValue(), 'RoleName', record);
                }
            });

            var len = f.length;
            return function(record) {
                for (var i = 0; i < len; i++) {
                    if (!f[i].filter(record)) {
                        return false;
                    }
                }
                return true
            };
        }

        function ConfirmDeletion() {
            Ext.Msg.confirm('<asp:Literal runat="server" Text="<%$ Resources:MBConfirm%>" />', '<asp:Literal runat="server" Text="<%$ Resources:MBSureDelete %>" />', DeleteConfirmed);
        }

        function btnDeleteSelected_Clicked() {
            if (Ext.getCmp('grvRoles').hasSelection()) {
                ConfirmDeletion();
            }
        }

        function DeleteConfirmed(btn) {
            if (btn == "yes")
                Pap.DeleteSelectedRoles();
        }
        
    </script>

    <ext:FitLayout runat="server">
        <ext:FormPanel ID="MainForm" runat="server" AutoScroll="true" Title="All Roles" meta:resourcekey="MainFormResource1">
            <Body>
                <ext:Store runat="server" ID="storeRoles" AutoLoad="True">
                    <Reader>
                        <ext:JsonReader ReaderID="RoleID">
                            <Fields>
                                <ext:RecordField Name="RoleName" />
                                <ext:RecordField Name="RoleID" />
                            </Fields>
                        </ext:JsonReader>
                    </Reader>
                </ext:Store>
                <ext:FitLayout runat="server">
                    <ext:GridPanel runat="server" ID="grvRoles" IDMode="Static" StoreID="storeRoles"
                        Title="Roles List" AutoWidth="True" TrackMouseOver="True" StripeRows="True" meta:resourcekey="grvRolesResource1"
                        SelectionSavingBuffer="10">
                        <ColumnModel>
                            <Columns>
                                <ext:Column Header="<%$ Resources:HeaderRoleName %>" DataIndex="RoleName" Sortable="True" />
                                <ext:CommandColumn Width="30px" Align="Center" Hideable="False" Sortable="True">
                                    <Commands>
                                        <ext:GridCommand CommandName="Edit" Icon="NoteEdit" IconCls="icon-noteedit">
                                            <ToolTip Text="<%$ Resources:CommandEditToolTip %>" />
                                        </ext:GridCommand>
                                    </Commands>
                                </ext:CommandColumn>
                            </Columns>
                        </ColumnModel>
                        <View>
                            <ext:GridView runat="server" meta:resourcekey="GridViewResource1">
                                <HeaderRows>
                                    <ext:HeaderRow>
                                        <Columns>
                                            <ext:HeaderColumn />
                                            <ext:HeaderColumn>
                                                <Component>
                                                    <ext:TextField runat="server" ID="txtRoleName" EnableKeyEvents="True" IDMode="Static"
                                                        meta:resourcekey="txtRoleNameResource1">
                                                        <Listeners>
                                                            <KeyUp Handler="ApplyFilter(#{storeRoles});" Buffer="250" />
                                                        </Listeners>
                                                    </ext:TextField>
                                                </Component>
                                            </ext:HeaderColumn>
                                        </Columns>
                                    </ext:HeaderRow>
                                </HeaderRows>
                            </ext:GridView>
                        </View>
                        <AjaxEvents>
                            <Command OnEvent="GrvRoles_Command">
                                <ExtraParams>
                                    <ext:Parameter Name="CommandName" Value="command" Mode="Raw" Encode="False" />
                                    <ext:Parameter Name="ID" Value="record.data.RoleID" Mode="Raw" Encode="False" />
                                </ExtraParams>
                            </Command>
                        </AjaxEvents>
                        <SelectionModel>
                            <ext:CheckboxSelectionModel runat="server">
                                <CustomConfig>
                                    <ext:ConfigItem Name="checkOnly" Value="true" Mode="Raw" Encode="False" />
                                </CustomConfig>
                            </ext:CheckboxSelectionModel>
                        </SelectionModel>
                        <TopBar>
                            <ext:Toolbar runat="server" meta:resourcekey="ToolbarResource2">
                                <Items>
                                    <ext:Button runat="server" ID="btnDelete" Icon="Delete" Text="Delete Selected" meta:resourcekey="btnDeleteResource1">
                                        <Listeners>
                                            <Click Handler="btnDeleteSelected_Clicked()" />
                                        </Listeners>
                                    </ext:Button>
                                </Items>
                            </ext:Toolbar>
                        </TopBar>
                        <BottomBar>
                            <ext:PagingToolbar StoreID="storeRoles" runat="server" PageSize="10" DisplayInfo="True"
                                meta:resourcekey="PagingToolbarResource1">
                                <Listeners>
                                    <Change Handler="GridRefreshed()" />
                                </Listeners>
                            </ext:PagingToolbar>
                        </BottomBar>
                    </ext:GridPanel>
                </ext:FitLayout>
            </Body>
        </ext:FormPanel>
    </ext:FitLayout>
</asp:Content>
